Skip to content

hosted-worker: refuse oversized kv PUT before buffering the body (#11332) - #11336

Merged
dezren39 merged 3 commits into
mainfrom
sweep/11332-user-do-body-cap
Nov 17, 2026
Merged

dezren39 merged 3 commits into
mainfrom
sweep/11332-user-do-body-cap

Conversation

@dezren39

@dezren39 dezren39 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes #11332.

What

The KV PUT path in pkgs/id/hosted-worker/src/user-do.ts called req.text() before assertWritable, so an oversized body was fully buffered before the storage ceiling check.

  • Compute headroom first: ceiling - usage + prior value bytes.
  • If a declared Content-Length exceeds headroom, return 413 ceiling_exceeded without reading the body.
  • Otherwise read through a capped reader that stops (413) as soon as the body exceeds headroom.
  • assertWritable stays as the authoritative check. Under-cap writes and overwrites are unchanged.

Blob PUT is deliberately left as is: it must hash the bytes first because a re-upload of an already-referenced blob has zero storage delta and must stay allowed at cap.

Tests

  • kv PUT over headroom is refused early on declared length, and by a capped read when chunked
  • kv overwrite headroom counts the prior value
  • Existing at-cap and metering tests unchanged.

node --test test/routing.test.ts test/blobs.test.ts test/usage.test.ts test/currency.test.ts: 22/22 pass.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 17, 2026 20:09
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c8dba748-5377-4ffb-a01a-63572048597e
Commits

Reviewing files that changed from the base of the PR and between cb96495 and 48878de.

Files selected for processing: 2

  • pkgs/id/hosted-worker/src/user-do.ts
  • pkgs/id/hosted-worker/test/usage.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hosted-worker user-do: KV and blob PUT buffer the whole request body before the storage ceiling check

1 participant